﻿(function () {

    layui.use(["layer", "jquery", "form", "laydate"], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var laydate = layui.laydate;

        $(document).ready(function () {
            $("#btnRelease").click(onReleaseBtnClick);
        });

        laydate.render({
            elem: '#txtSearchDate',
            value: (new Date()),
            isInitValue: true,
            showBottom: false
        });

        function onReleaseBtnClick() {
            layer.confirm("确定要发布订单吗？",
                { icon: 3, title: "满堂创品", offset: "20%" },
                function () {
                    var loadingIndex = layer.msg(addStyle("正在处理 ......"),
                        { icon: 16, shade: 0.01, offset: ["25%"], time: false });
                    $.ajax("/Order/ReleaseOrder", {
                        method: "POST",
                        data: "date=" + $("#txtSearchDate").val(),
                        complete: function (jqXHR, textStatus) {
                            layer.close(loadingIndex);
                        },
                        success: function (data, textStatus, jqXHR) {
                            if (data.Success == true) {
                                layer.msg(addStyle("发布订单成功！"), {
                                    icon: 1, time: 1 * 1000, offset: ["25%"]
                                });
                            } else {
                                layer.msg(addStyle("发布订单失败: " + data.Msg),
                                    { icon: 2, time: 3 * 1000, offset: ["25%"], closeBtn: true }
                                );
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.msg(addStyle("系统错误，请联系管理员！"),
                                { icon: 2, time: 3 * 1000, offset: ["25%"], closeBtn: true });
                        }
                    });
                }
            );
        }

        function addStyle(str) {
            return '<span style="font-size: 16px;">' + str + '</span>';
        }
    });

})();